<%@ page language = "java"%>
<%@ page import = "com.scalar.chiptrack.utils.ConfigManager,
                   com.scalar.chiptrack.users.User,
                   com.scalar.chiptrack.users.Functionality,
                   com.scalar.chiptrack.utils.StringUtils,
                   java.util.ArrayList,
                   org.apache.struts.util.LabelValueBean,
                   com.scalar.chiptrack.sales.receivables.CustomerMaintenance,
                   com.scalar.chiptrack.sales.receivables.CustomerMaintenanceList,
                   com.scalar.chiptrack.sales.receivables.CustomerAddressList,
                   com.scalar.chiptrack.sales.receivables.CustomerAddress,
                   com.scalar.chiptrack.sales.Customer"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<HEAD>
	<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
	<TITLE>Scalarsoft - ChipTrac</TITLE>
	<LINK href='<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css' type="text/css" rel='stylesheet'>

<!-- Validations starts here -->

<SCRIPT language = "javascript" src = "<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</SCRIPT>

<SCRIPT language="javascript">

var keys                = new Array();
var comments            = new Array();
var unitCost            = new Array();
var customerIdsArray    = new Array();
var customerNameArray   = new Array();
var unitPartKeys        = new Array();

function addLineItem()
{
    calculateTotal();
    if ( checkBeforeSubmit() == false )
    {
        return;
    }
    else
    {
        enableFields(); // To Enable all disabled fields

        form['salesOrderInvoice.invoiceNumber'].disabled=false;
        form.action='<%=chipTracContext%>/salesOrderInvoice.do?action=addLineItem';
        form.submit();
    }
}
function changeDocType()
{
    form.action='<%=chipTracContext%>/salesOrderInvoice.do?action=loadInvoiceByDocType';
    form.submit();
}

function confirmInvoice()
{
    var selectedDocType   = "";

    //calculateTotal(); // To calculate Totals.

    if ( calculateTotal() == false )       //Added by phani on 26th Mar 2004
    {
        return;
    }

    if ( checkBeforeSubmit() == false )
    {
        return;
    }
    else
    {
        enableFields(); // To enable all disabled fields.
        selectedDocType = form['salesOrderInvoice.invoiceDocumentTypeId'].selectedIndex;
        form['salesOrderInvoice.invoiceDocumentTypeIdLabel'].value = form['salesOrderInvoice.invoiceDocumentTypeId'].options[selectedDocType].innerText;

        var totalLineItems = form.count.value;

        // Check all the line items that have been loaded from the database.
        for( k = 0; k < totalLineItems; k ++ )
        {
            if( form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + k + '].disableCheckBox'].value == 'true' )
            {
                form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + k + '].lineItemSave'].checked = true;
            }
        }


        form.action='<%=chipTracContext%>/salesOrderInvoice.do?action=confirm';
        form.submit();
    }
}

function enableFields()
{
    var count = form.count.value;
    var selectedStatus;


    form['salesOrderInvoice.invoiceNumber'].disabled=false;
    form['salesOrderInvoice.invoiceDocumentTypeId'].disabled=false;
    form['salesOrderInvoice.postingDate'].disabled = false;

    form['salesOrderInvoice.subTotal'].disabled = false;
    form['salesOrderInvoice.total'].disabled = false;
    form['salesOrderInvoice.accountAmount'].disabled = false;

    // Invoice Lineitem related Fields
    for( i = 0; i < count; i++ )
    {
        form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitCost'].disabled = false;
        form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].extendedPrice'].disabled = false;
    }
}

function calculateExtendedPrice()
{
    var count = form.count.value;

    var unitPrice       = 0.00;
    var quantity        = 0.00;
    var extendedPrice   = 0.00;
    var markDown        = 0.00;

    for( i=0; i< count; i++ )
    {
        if ( form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].extendedPrice'].value == '' || form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].extendedPrice'].value == '0' )
        {
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].extendedPrice'].value = '0.00';
        }

        unitPrice =  form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitPrice'].value;
        quantity = form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].quantity'].value;
        extendedPrice = form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].extendedPrice'].value;
        markDown = form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].markDown'].value;

        if( ( extendedPrice == '0' ) || ( extendedPrice == '' ) || ( quantity == '0' ) || ( quantity == '' ) || ( quantity == '0.00' ) )
        {
            //form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].extendedPrice'].value = parseDec( round( ( ( parseFloat( parseFloat( quantity ) * parseFloat( unitPrice ) ) - parseFloat( markDown ) ) ) ), 2, '.'  );
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].extendedPrice'].value = parseDec( round( ( ( parseFloat( parseFloat( unitPrice ) - parseFloat( markDown ) ) * parseFloat( quantity ) ) ) ), 2, '.'  );
        }
        else if ( ( extendedPrice != '0' ) && ( quantity != '0' )  &&  ( unitPrice != '0' )  )
        {
            if( ( parseFloat( extendedPrice) / parseFloat( quantity ) ) != parseFloat( unitPrice ) )
            {
                //form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitPrice'].value = parseDec( round(  parseFloat( ( parseFloat( extendedPrice ) * parseFloat( quantity ) ) + parseFloat( markDown ) ) ), 2, '.'  );
                form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitPrice'].value = parseDec( round(  parseFloat( parseFloat( extendedPrice ) / parseFloat( quantity ) ) ), 2, '.'  );
            }
        }
     }
}

function calculateTotal()
{

    var pa = document.getElementById("lineItemErrors");
    pa.innerHTML = "";

    // Totals Calculation starts here.
    var count           = form.count.value;
    var quantity        = 0;
    var unitPrice       = 0.00;
    var extendedPrice   = 0.00;
    var subTotal        = 0.00;
    var total           = 0.00;
    var onAccount       = 0.00;
    var markDown        = 0.00;

    if ( form['salesOrderInvoice.tradeDiscount'].value == '' || form['salesOrderInvoice.tradeDiscount'].value == '0' ||
         form['salesOrderInvoice.tradeDiscount'].value < 0 )
    {
        form['salesOrderInvoice.tradeDiscount'].value = '0.00';
    }
    else
    {
         form['salesOrderInvoice.tradeDiscount'].value = parseMoney (form['salesOrderInvoice.tradeDiscount'].value);
    }

    if ( form['salesOrderInvoice.freight'].value == '' || form['salesOrderInvoice.freight'].value == '0' ||
         form['salesOrderInvoice.freight'].value < 0 )
    {
         form['salesOrderInvoice.freight'].value = '0.00';
    }
    else
    {
         form['salesOrderInvoice.freight'].value = parseMoney (form['salesOrderInvoice.freight'].value);
    }

    if ( form['salesOrderInvoice.miscellaneous'].value == '' || form['salesOrderInvoice.miscellaneous'].value == '0' ||
         form['salesOrderInvoice.miscellaneous'].value < 0 )
    {
         form['salesOrderInvoice.miscellaneous'].value = '0.00';
    }
    else
    {
         form['salesOrderInvoice.miscellaneous'].value = parseMoney (form['salesOrderInvoice.miscellaneous'].value);
    }

    if ( form['salesOrderInvoice.tax'].value == '' || form['salesOrderInvoice.tax'].value == '0' ||
         form['salesOrderInvoice.tax'].value < 0 )
    {
         form['salesOrderInvoice.tax'].value = '0.00';
    }
    else
    {
         form['salesOrderInvoice.tax'].value = parseMoney (form['salesOrderInvoice.tax'].value);
    }

    if ( form['salesOrderInvoice.amountReceived'].value == '' || form['salesOrderInvoice.amountReceived'].value == '0' ||
         form['salesOrderInvoice.amountReceived'].value < 0 )
    {
         form['salesOrderInvoice.amountReceived'].value = '0.00';
    }
    else
    {
         form['salesOrderInvoice.amountReceived'].value = parseMoney (form['salesOrderInvoice.amountReceived'].value);
    }

    if ( form['salesOrderInvoice.discountTaken'].value == '' || form['salesOrderInvoice.discountTaken'].value == '0' ||
         form['salesOrderInvoice.discountTaken'].value < 0 )
    {
         form['salesOrderInvoice.discountTaken'].value = '0.00';
    } else {
         form['salesOrderInvoice.discountTaken'].value = parseMoney (form['salesOrderInvoice.discountTaken'].value);
    }

    for( i=0; i < count; ++i )
    {
       // Setting the feilds to 0 if the user does not enter anything.
        if ( form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitPrice'].value == '' || form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitPrice'].value == '0' ||
             form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitPrice'].value < 0 )
        {
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitPrice'].value = '0.00';
        }
        else
        {
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitPrice'].value =
                parseMoney (form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitPrice'].value);
        }

       if ( form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].quantity'].value == '' ||
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].quantity'].value < 0 )
        {
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].quantity'].value = '0';
        }                    //added by phani 26/03/2004
        else if ( parseFloat (form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].quantity'].value) >
            parseFloat (form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].quantity'].defaultValue) )
        {
                pa.innerHTML = "Quantity cannot be greater than the Quantity Requested in Line Item No " + ( i + 1 );
                form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].quantity'].value = form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].quantity'].defaultValue;
                return false;
        }    //added by phani 12/04/2004
        else
        {
           form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].quantity'].value =
                 parseDec (form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].quantity'].value, 0);
        }

        if ( form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].markDown'].value == '' || form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].markDown'].value == '0' ||
             form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].markDown'].value < 0 )
        {
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].markDown'].value = '0.00';
        }
        else
        {
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].markDown'].value =
                parseMoney (form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].markDown'].value);
        }

        unitPrice =  form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitPrice'].value;
        quantity = form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].quantity'].value;
        markDown = form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].markDown'].value;

        if ( parseFloat (form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].markDown'].value) >
                parseFloat (form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitPrice'].value) )
        {

            pa.innerHTML = "The markdown cannot be greater than the unit price in Line Item No " + ( i + 1 );
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].markDown'].focus ();
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].markDown'].select ();
            return false;
        }

        //extendedPrice = ( parseFloat( quantity ) * parseFloat(  unitPrice ) - parseFloat( markDown )  ) ;
        extendedPrice = ( parseFloat( quantity ) * ( parseFloat(  unitPrice ) - parseFloat( markDown ) )  ) ; //Phani on 25/03/2004
        form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].extendedPrice'].value = parseDec( round( parseFloat( extendedPrice ) ), 2, '.' );
        subTotal = parseDec( round( ( parseFloat( subTotal ) + parseFloat( extendedPrice ) ) ), 2, '.' );
    }

    form['salesOrderInvoice.subTotal'].value = parseDec( round( parseFloat( subTotal ) ), 2, '.' );

    total = ( parseFloat( form['salesOrderInvoice.freight'].value ) + parseFloat( form['salesOrderInvoice.miscellaneous'].value ) + parseFloat( form['salesOrderInvoice.tax'].value - parseFloat( form['salesOrderInvoice.tradeDiscount'].value ) )  );

    form['salesOrderInvoice.total'].value = parseDec( round( parseFloat( ( parseFloat( total ) + ( parseFloat( subTotal ) ) ) ) ), 2, '.' );

    form['salesOrderInvoice.accountAmount'].value = parseDec( round( ( parseFloat( form['salesOrderInvoice.total'].value ) - parseFloat( form['salesOrderInvoice.amountReceived'].value ) - parseFloat( form['salesOrderInvoice.discountTaken'].value ) ) ), 2, '.' );
}

function reset()
{
    form.reset();
    formatAmountsOnLoad();
}

<%
    if( request.getAttribute("partNumberDescriptions") != null )
    {
         StringBuffer strBuffer = null;
         java.util.HashMap mapComments = null;
         try{
                 mapComments = (java.util.HashMap) request.getAttribute("partNumberDescriptions");
                 java.util.Iterator mapKeyIterator = mapComments.keySet().iterator();
                 int count = 0;
                 strBuffer = new StringBuffer();
                 while( mapKeyIterator.hasNext() )
                 {
                     Object key = mapKeyIterator.next();
                     strBuffer.append("keys[").append(count).append("]='").append(key).append("';\n");
                     //strBuffer.append("comments[").append(count).append("]='").append(StringUtils.escapeHTML((String)mapComments.get(key))).append("';\n");
                     out.print( "comments["+count+"]='");
                     if(mapComments.get(key)!=null){
                        out.print(StringUtils.escapeSpecialString((String)mapComments.get(key)) );
                     }
                     out.println("';");
                     count++;
                 }
            out.println(strBuffer.toString());
            }
            catch(Exception ex)
            {
                System.out.println(ex);
            }
     }

    if( request.getAttribute("partNumberCost") != null )
    {
         StringBuffer strBuffer = null;
         java.util.HashMap mapUnitCost = null;
         try{
                 mapUnitCost = (java.util.HashMap) request.getAttribute("partNumberCost");
                 java.util.Iterator mapKeyIterator = mapUnitCost.keySet().iterator();
                 int count = 0;
                 strBuffer = new StringBuffer();
                 while( mapKeyIterator.hasNext() )
                 {
                     Object key = mapKeyIterator.next();
                     //unitPartKeys
                     strBuffer.append("unitPartKeys[").append(count).append("]='").append(key).append("';\n");
                     out.print( "unitCost["+count+"]='");
                     if(mapUnitCost.get(key)!=null)
                     {
                        out.print(StringUtils.escapeSpecialString( (String) mapUnitCost.get(key)) );
                     }
                     out.println("';");
                     count++;
                 }
            out.println(strBuffer.toString());
            }
            catch(Exception ex)
            {
                System.out.println(ex);
            }
     }

    if( request.getAttribute("customerNameList") != null )
    {
        //CustomerMaintenance customerMaintenence = new CustomerMaintenance();
        //ArrayList customerMaintenanceList = new CustomerMaintenanceList();
        Customer customer = null;
        ArrayList customerList = null;

        try
        {
            customerList = ( ArrayList ) request.getAttribute("customerNameList");
        }
        catch(Exception e )
        {
            System.out.println(e);
        }
          try
         {
                StringBuffer customerIdsArray   = new StringBuffer();
                StringBuffer customerNameArray  = new StringBuffer();
                int arrayIndex = 0;

                for(int j = 0; j < customerList.size(); j++ )
                {
                    customer = (Customer) customerList.get( j );

                    customerIdsArray.append( "customerIdsArray[" +  arrayIndex  + "]=\"" + String.valueOf( customer.getCustomerId() ) + "\";\n" );
                    customerNameArray.append( "customerNameArray[" +  arrayIndex  + "]=\"" + customer.getCustomerName() + "\";\n" );

                     arrayIndex++;
                }
                out.println( customerIdsArray );
                out.println( customerNameArray );
            }
            catch(Exception ex)
            {
                System.out.println(ex);
            }
     }
%>

function checkBeforeSubmit()
{
    // This function checks for Mandatory fields before submitting the page.
    var count = form.count.value;
    var paInvoice =  document.getElementById("invoiceErrors");
    var paLineItem = document.getElementById("lineItemErrors");

    var docDate = form['salesOrderInvoice.documentDate'].value;
    var quotedDate = form['salesOrderInvoice.quotedDate'].value;
    var postingDate = form['salesOrderInvoice.postingDate'].value;
    var orderDate = form['salesOrderInvoice.orderDate'].value;

    paInvoice.innerHTML = "";
    paLineItem.innerHTML = "";

    //checking if the customer is selected
    if( form['salesOrderInvoice.customerId'].value == '0' )
    {
        if( form['salesOrderInvoice.customerId'].disabled == false )
        {
            paInvoice.innerHTML = " <li> Please Select Customer ID ";
            form['salesOrderInvoice.customerId'].focus();
        }
        return false;
    }
    /*
    else if ( form['salesOrderInvoice.customerName'].value == '' )
    {
        paInvoice.innerHTML = " <li> Please Enter Customer Name";
        form['salesOrderInvoice.customerName'].select();
        form['salesOrderInvoice.customerName'].focus();
        return false;
    }
    */
    //checking if location is selected
    else if ( form['salesOrderInvoice.locationCode'].value == '' )
    {
        paInvoice.innerHTML = " <li> Please Select Default Site";
        form['salesOrderInvoice.locationCode'].focus();
        return false;
    }
    //checking the document date format
    else if( !chkDate( docDate, "Document Date", 'Y' ) )
    {
        //commented by phani 01/04/2003
        //paInvoice.innerHTML = " <li> Please Enter Date in MM/DD/YYYY format ";
        paInvoice.innerHTML = errMsg;  //added by phani 01/04/2004
        form['salesOrderInvoice.documentDate'].select();
        form['salesOrderInvoice.documentDate'].focus();
        return false;
    }
    //checking the quote date format
    else if( !chkDate( quotedDate, "Quoted Date", 'N' ) )
    {
        //paInvoice.innerHTML = " <li> Please Enter Date in MM/DD/YYYY format ";
        paInvoice.innerHTML = errMsg;  //added by phani 01/04/2004
        form['salesOrderInvoice.quotedDate'].select();
        form['salesOrderInvoice.quotedDate'].focus();
        return false;
    }
    //checking the posting date format
    else if( !chkDate( postingDate, "Posting Date", 'N' )  && form['salesOrderInvoice.postingDate'].disabled == false )
    {
        //paInvoice.innerHTML = " <li> Please Enter Date in MM/DD/YYYY format ";
        paInvoice.innerHTML = errMsg;  //added by phani 01/04/2004
        form['salesOrderInvoice.postingDate'].select();
        form['salesOrderInvoice.postingDate'].focus();
        return false;
    }
    //checking the order date format
    else if( !chkDate( orderDate, "Order Date", 'N' ) )
    {
        //paInvoice.innerHTML = " <li> Please Enter Date in MM/DD/YYYY format ";
        paInvoice.innerHTML = errMsg;  //added by phani 01/04/2004
        form['salesOrderInvoice.orderDate'].select();
        form['salesOrderInvoice.orderDate'].focus();
        return false;
    }


    // Line Items
    for( i = 0; i < count; i++ )
    {
        /*
        if( form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].marketingPartNo'].value == '' )
        {
            paLineItem.innerHTML = " <li> Please Select Purchase Order Number in Line Item No " + parseInt(i + 1);
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].marketingPartNo'].focus();
            return false;
        }
        */
    }

	// to check description length
	for( i = 0; i < count; i++ )
    {
        if( form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].lineItemDescription'].value .length > 51)
        {
            paLineItem.innerHTML = " <li> Description length can not be more than 51 in Line Item " + parseInt(i + 1);
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].lineItemDescription'].focus();
			form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].lineItemDescription'].select();
            return false;
        }
    }

    if(	form['salesOrderInvoice.commentDescription'].value.length > 450 )
	{
		paLineItem.innerHTML = " <li> Comment length can not be more than 450 ";
        return false;
	}

}

function itemOnChange( selectedItem )
{

    // This Function is called when the User selects Marketing Part Number.
    // Shows the Corresponding Manufacturing part Number from the List based on Index value.

    var selectedItemNumber;
    var tempSelectedName = selectedItem.name;
    var marketingPartNoValue;
    var pa = document.getElementById("lineItemErrors");
    pa.innerHTML = "";

    var tempStart = tempSelectedName.lastIndexOf("["); // Get the Starting index no of [
    var tempEnd = tempSelectedName.lastIndexOf("]");   // Get the Ending index no of ]
    var indexNo = parseInt ( tempSelectedName.substring( tempStart + 1, tempEnd ) );

    marketingPartNoValue = form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + indexNo + '].marketingPartNo'].value;

    for( i = 0; i < keys.length; i++ )
    {
        // If Marketing part number is equal to the Po number selected by the user.
        if( keys[i].toLowerCase().trim() == marketingPartNoValue.toLowerCase().trim() )
        {
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + indexNo + '].lineItemDescription'].value =  comments[i];
            //form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + indexNo + '].unitCost'].value =  parseDec( round( unitCost[i] ), 2, '.' );
            //Written this loop as the Cost array is diffent than the item array.
            for( j = 0; j < unitPartKeys.length; j++ )
            {
                // If Marketing part number is equal to the Po number selected by the user.
                if( unitPartKeys[j].toLowerCase().trim() == marketingPartNoValue.toLowerCase().trim() )
                {
                    form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + indexNo + '].unitCost'].value = parseDec( round( unitCost[j] ), 2, '.' );
                    break;
                }
                else
                {
                   form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + indexNo + '].unitCost'].value =  '0.00';
                }
            }
            return;
        }
        else
        {
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + indexNo + '].lineItemDescription'].value =  '';

        }
    }
}

/*
function customerOnChange( selectedItem )
{

    // This Function is called when the User selects Customer Id.
    // Shows the Corresponding Customer Id from the List based on Index value.

    var selectedCustomerId;
    var tempSelectedName = selectedItem.name;
    var customerValue;

    var tempStart = tempSelectedName.lastIndexOf("["); // Get the Starting index no of [
    var tempEnd = tempSelectedName.lastIndexOf("]");   // Get the Ending index no of ]
    var indexNo = parseInt ( tempSelectedName.substring( tempStart + 1, tempEnd ) );

    customerValue = form['salesOrderInvoice.customerId'].value;

    for( i = 0; i < customerIdsArray.length; i++ )
    {
        // If Customer number is equal to the Customer number selected by the user.
        if( customerIdsArray[i].toLowerCase().trim() == customerValue.toLowerCase().trim() )
        {
            form['salesOrderInvoice.customerName'].value =  customerNameArray[i];
            return;
        }
        else
        {
            form['salesOrderInvoice.customerName'].value =  '';
        }
    }
}
*/

function formatAmountsOnLoad()
{

    for (i = 0; i < form.count.value; i ++ )
    {
        form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitCost'].value = parseDec( round( form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitCost'].value ), 2, '.' );
        form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitPrice'].value = parseDec( round( form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].unitPrice'].value ), 2, '.' );
        form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].markDown'].value = parseDec( round( form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].markDown'].value ), 2, '.' );
        form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].extendedPrice'].value = parseDec( round( form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + i + '].extendedPrice'].value ), 2, '.' );
    }
        form['salesOrderInvoice.subTotal'].value = parseDec( round( form['salesOrderInvoice.subTotal'].value ), 2, '.' );
        form['salesOrderInvoice.tradeDiscount'].value = parseDec( round( form['salesOrderInvoice.tradeDiscount'].value ), 2, '.' );
        form['salesOrderInvoice.freight'].value = parseDec( round( form['salesOrderInvoice.freight'].value ), 2, '.' );
        form['salesOrderInvoice.miscellaneous'].value = parseDec( round( form['salesOrderInvoice.miscellaneous'].value ), 2, '.' );
        form['salesOrderInvoice.tax'].value = parseDec( round( form['salesOrderInvoice.tax'].value ), 2, '.' );
        form['salesOrderInvoice.total'].value = parseDec( round( form['salesOrderInvoice.total'].value ), 2, '.' );
        form['salesOrderInvoice.amountReceived'].value = parseDec( round( form['salesOrderInvoice.amountReceived'].value ), 2, '.' );
        form['salesOrderInvoice.discountTaken'].value = parseDec( round( form['salesOrderInvoice.discountTaken'].value ), 2, '.' );
        form['salesOrderInvoice.accountAmount'].value = parseDec( round( form['salesOrderInvoice.accountAmount'].value ), 2, '.' );
        var totalLineItems = form.count.value;

        // uncheck all the line items.
        for( k = 0; k < totalLineItems; k++ )
        {
            if( form[ 'salesOrderInvoice.selectedSONumber' ].disabled == true )
            {
                //For Auto Invoice disabling those line items that are not selected
                if( form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + k + '].lineItemSave'].checked == false )
                {
                    form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + k + '].unitPrice'].disabled = true;
                }
                else
                {
                    form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + k + '].unitPrice'].disabled = false;
                }

            }
            else
            {
                //For a normal sales invoice Unchecking the line items
                form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + k + '].unitPrice'].disabled = true;
                form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + k + '].lineItemSave'].checked = false;
            }
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + k + '].lineItemDescription'].disabled = true;
            //form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + k + '].markDown'].disabled = true;
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + k + '].extendedPrice'].disabled = true;
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + k + '].quantity'].disabled = true;
        }
}

function customerOnChange( selectedItem )
{
    // This Function is called when the User Selects the Customer From the List.
    var selectedCustomerId;
    var tempSelectedName = selectedItem.name;
    var customerValue;

    customerValue = form['salesOrderInvoice.customerId'].value;

    for( i = 0; i < customerIdsArray.length; i++ )
    {
        // If Customer number is equal to the Customer number selected by the user.
        if( customerIdsArray[i].toLowerCase().trim() == customerValue.toLowerCase().trim() )
        {
            form['salesOrderInvoice.customerName'].value =  customerNameArray[i];
            break;
        }
        else
        {
            form['salesOrderInvoice.customerName'].value =  '';
        }
    }

    form['salesOrderInvoice.salesOrderInvoiceLineItemList[0].lineItemDescription'].value = '';
    form['salesOrderInvoice.salesOrderInvoiceLineItemList[0].quantity'].value = '0';
    form['salesOrderInvoice.salesOrderInvoiceLineItemList[0].extendedPrice'].value = '0.00';
    form['salesOrderInvoice.salesOrderInvoiceLineItemList[0].unitPrice'].value = '0.00';
    form['salesOrderInvoice.salesOrderInvoiceLineItemList[0].markDown'].value = '0.00';

    form['salesOrderInvoice.subTotal'].value = '0.00';
    form['salesOrderInvoice.tradeDiscount'].value = '0.00';
    form['salesOrderInvoice.freight'].value = '0.00';
    form['salesOrderInvoice.miscellaneous'].value = '0.00';
    form['salesOrderInvoice.tax'].value = '0.00';
    form['salesOrderInvoice.total'].value = '0.00';

    form['salesOrderInvoice.amountReceived'].value = '0.00';
    form['salesOrderInvoice.discountTaken'].value = '0.00';
    form['salesOrderInvoice.accountAmount'].value = '0.00';

    form['salesOrderInvoice.invoiceNumber'].disabled=false;
    form.action='<%=chipTracContext%>/salesOrderInvoice.do?action=loadOrdersByCustomer';

    form.submit();
}

function onCheckBoxChange( rowNo )
{
	var totalLineItems = form.count.value;
	var sum = 0.00;
	var total = 0.00;
	// added by raju on 5/5/2004
	for(j = 0; j < totalLineItems; j++)
	{
		if( form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + j + '].lineItemSave'].checked == true )
		{
			sum = parseFloat(sum)+ parseFloat(form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + j + '].extendedPrice'].value);
		}
	}
	form['salesOrderInvoice.subTotal'].value = parseDec( round( sum ), 2, '.' );

	total = ( ( parseFloat( form['salesOrderInvoice.freight'].value ) + parseFloat( form['salesOrderInvoice.miscellaneous'].value ) + parseFloat( form['salesOrderInvoice.tax'].value ) - parseFloat( form['salesOrderInvoice.tradeDiscount'].value ) ) + parseFloat( sum ) );
	form['salesOrderInvoice.total'].value = parseDec( round( total  ), 2, '.' );

    form['salesOrderInvoice.accountAmount'].value = parseDec( round( ( parseFloat( form['salesOrderInvoice.total'].value ) - parseFloat( form['salesOrderInvoice.amountReceived'].value ) - parseFloat( form['salesOrderInvoice.discountTaken'].value ) ) ), 2, '.' );


	if( form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].lineItemSave'].checked == true )
    {
        if( form['salesOrderInvoice.selectedSONumber'].disabled == false )
        {
		    form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].lineItemDescription'].disabled = false;
		    form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].unitPrice'].disabled = false;
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].markDown'].disabled = false;
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].extendedPrice'].disabled = false;
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].quantity'].disabled = false;
        }
        else
        {
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].unitPrice'].disabled = false;
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].markDown'].disabled = false;
        }
    }
    else
    {
        if( form['salesOrderInvoice.selectedSONumber'].disabled == true )
        {
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].unitPrice'].disabled = true;
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].markDown'].disabled = true;
        }
        else
        {
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].lineItemDescription'].disabled = true;
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].unitPrice'].disabled = true;
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].markDown'].disabled = true;
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].extendedPrice'].disabled = true;
            form['salesOrderInvoice.salesOrderInvoiceLineItemList[' + rowNo + '].quantity'].disabled = true;
        }
    }
}

function loadBySONumber()
{
    // This Function is called when the User Selects and submits the Sales Order no From the List.
    var docNumber;
    var paLineItem = document.getElementById("lineItemErrors");
    paLineItem.innerHTML = "";

    //calculating the total amount
    if ( calculateTotal() == false )
    {
        return;
    }

    // Check if SO Number is selected or not.
    if( form['salesOrderInvoice.selectedSONumber'].value == '' )
    {
        paLineItem.innerHTML = "<li> Select a Sales Order Number to Add Line Items";
        form['salesOrderInvoice.selectedSONumber'].focus();
    }
    else
    {
        form['salesOrderInvoice.invoiceNumber'].disabled=false;
        form.action='<%=chipTracContext%>/salesOrderInvoice.do?action=loadBySO';
        form.submit();
    }
}
// added by raju on 3/21/2004 to check line item description length .

function checkDescriptionLength(description)
{
	if(	description.value.length > 50 )
	{
		event.returnValue = false;
	}
}
// added by Phani on 25th Mar 2004 to check comment length .
function checkCommentLength(comment)
{
    if(	comment.value.length >= 450 )
	{
		event.returnValue = false;
	}
}

   //KumaraSwamy added this date picker functionality on 1st Sep, 2004
	var dateElement = "";
	function openCalendar(dateValue)
	{
		dateElement = dateValue;
		newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
		newWindow.moveTo(550,180);
		newWindow.focus();
	}
    function assignDate(passedValue)
	{
		dateElement.value=passedValue;
		window.focus();
	}
</SCRIPT>
<!-- Validations ends here -->
<% int i = 0; /*variable used to assign Serial numers */ %>
</HEAD>
<BODY bgColor="#ffffff" topMargin='0' leftMargin='0' marginHeight='0' marginWidth='0' onload="javascript:formatAmountsOnLoad();">

<!-- Top header start here -->
	<%@ include file = "/jsp/includes/header.jsp"%>
<!-- Top header ends here -->

<P>
<TABLE BORDER="0" width="100%" cellSpacing=0 cellPadding=0>
<TR>
<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
<!-- Side Navigation Starts Here  -->
	<%@ include file="/jsp/sales/sales_menu.jsp"%>
<!-- Side Navigation Ends Here -->
</TD>
<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<!-- SiteMap Tag -->
<!-- chiptrack:sitemap styleClass="NArialS"/ -->

<chiptrack:permission functionality='<%=Functionality.SALES_ORDER_INVOICE%>'
    action='<%=User.USER_ACTION_MODIFY%>' styleClass="NArialL" >
</chiptrack:permission>

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<!-- from here your body starts -->
<P>
<html:form name="salesOrderInvoiceForm" action="/salesOrderInvoice.do?action=search" method="post" type="com.scalar.chiptrack.sales.forms.SalesOrderInvoiceForm">
    <TABLE BORDER="0" WIDTH="100%">

      <TR>
        <TD WIDTH="100%">
        <TABLE BORDER="0" WIDTH="100%">
            <TR>
              <TD WIDTH="100%" class="NArialW">
                <P ALIGN="CENTER">Sales Invoice
              </TD>
            </TR>
            <TR>
              <TD WIDTH="100%">&nbsp;</TD>
            </TR>
            <TR>
              <TD><chiptrack:info styleClass="NArialL" /></TD>
            </TR>
            <TR>
              <TD><chiptrack:errors styleClass="NArialL" /></TD>
            </TR>
            <TR>
              <TD><chiptrack:moreErrorInfo styleClass="NArialL" /></TD>
            </TR>
            <TR>
              <TD colspan='5' align="left" class='NArialL'><FONT id="errors" styleClass="NArialL" color='FF0000'></FONT>
              </TD>
            </TR>
    </TABLE>
    </TD>
  </TR>
  <TR>
    <TD WIDTH="100%">
    <nested:nest property="salesOrderInvoice">
    <TABLE BORDER="0" WIDTH="100%" CLASS="NArialL" align="center">
	    <TR>
          <TD WIDTH = "100%" COLSPAN="9">
            <FONT id="invoiceErrors" styleClass="NArialL" color="red" size="1"></FONT>
          </TD>
        </TR>
        <TR>
		  <TD WIDTH="7%">&nbsp;</TD>
		  <TD WIDTH="14%">Document No:</TD>
		  <TD WIDTH="4%">&nbsp;</TD>
		  <TD WIDTH="16%">
            <nested:text property="invoiceNumber" styleClass="txfield" size="25" disabled="true" readonly="true"/>
		  </TD>
		  <TD WIDTH="4%">&nbsp;</TD>
		  <TD WIDTH="14%">Document Type:</TD>
		  <TD WIDTH="2%">&nbsp;</TD>
		  <TD WIDTH="18%">
            <nested:hidden property="invoiceDocumentTypeIdLabel" />
            <logic:equal name="action" value="edit">
                <nested:select property="invoiceDocumentTypeId" styleClass="txfield" disabled="true">
                    <html:options collection = "documentType" property="value" labelProperty="label"/>
                </nested:select>
             </logic:equal>
            <logic:notEqual name="action" value="edit">
                <nested:select property="invoiceDocumentTypeId" styleClass="txfield" onchange="javascript:changeDocType();">
                    <html:options collection = "documentType" property="value" labelProperty="label"/>
                </nested:select>
             </logic:notEqual>
             &nbsp;&nbsp;&nbsp;<nested:checkbox property="hold" value = "true" styleClass="txfield" />&nbsp;Hold
          </TD>
		  <TD WIDTH="17%">&nbsp;</TD>
		</TR>
		<TR>
		  <TD WIDTH="7%">&nbsp;</TD>
		  <TD WIDTH="14%">Customer Name:&nbsp;<font color ="red" style="arial">*</font></TD>
		  <TD WIDTH="3%">&nbsp;</TD>
		  <TD WIDTH="16%">
            <logic:equal name="action" value="edit" >
                <nested:select property="customerId" styleClass="txfield" disabled="true">
                    <html:options collection = "customerIdList" property="value" labelProperty="label"/>
                </nested:select>
            </logic:equal>
            <logic:notEqual name="action" value="edit" >
                <nested:select property="customerId" styleClass="txfield" onchange="javascript:customerOnChange(this);">
                    <html:options collection = "customerIdList" property="value" labelProperty="label"/>
                </nested:select>
            </logic:notEqual>
            <nested:hidden property="customerName" />
		  </TD>
		  <TD WIDTH="4%">&nbsp;</TD>
		  <TD WIDTH="14%">Customer PO No:</TD>
		  <TD WIDTH="2%">&nbsp;</TD>
		  <TD WIDTH="18%">
            <nested:text property="customerPONumber" size ="23" styleClass="txField" maxlength="21" disabled="true" />&nbsp;
          </TD>
		  <TD WIDTH="17%">&nbsp;</TD>
		</TR>
		<TR>
		  <TD WIDTH="7%">&nbsp;</TD>
		  <TD WIDTH="14%">Quote No:&nbsp;</TD>
		  <TD WIDTH="4%">&nbsp;</TD>
		  <TD WIDTH="16%">
            <nested:text property="quoteNumber" size ="23" styleClass="txField" maxlength="21" />
          </TD>
		  <TD WIDTH="4%">&nbsp;</TD>
		  <TD WIDTH="14%">Default Site:&nbsp;<font color ="red" style="arial">*</font></TD>
		  <TD WIDTH="2%">&nbsp;</TD>
		  <TD WIDTH="18%">
            <nested:text property="locationCode" disabled="true" styleClass="txfield"></nested:text>
            <!-- nested : select property="locationCode" styleClass="txfield" disabled="true" >
                < html : options collection = "siteList" property="value" labelProperty="label" />
            < / nested : select -->
		  </TD>
		  <TD WIDTH="17%">&nbsp;</TD>
		</TR>
		<TR>
		  <TD WIDTH="7%">&nbsp;</TD>
		  <TD WIDTH="14%">Date:&nbsp;<font color ="red" style="arial">*</font></TD>
		  <TD WIDTH="4%">&nbsp;</TD>
		  <TD WIDTH="16%">
            <nested:text property="documentDate" size ="12" styleClass="txField" maxlength="10" />
            <a href="javascript:openCalendar(document.salesOrderInvoiceForm['salesOrderInvoice.documentDate'])">
		    <img onMouseOver="window.status='Click here to select date';return true"  onMouseOut="window.status='';return true" border="0" align='center'
		    src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
          </TD>
		  <TD WIDTH="4%">&nbsp;</TD>
		  <TD WIDTH="14%">Quote Date:</TD>
		  <TD WIDTH="2%">&nbsp;</TD>
		  <TD WIDTH="18%">
            <nested:text property="quotedDate" size ="12" styleClass="txField" maxlength="10" />
            <a href="javascript:openCalendar(document.salesOrderInvoiceForm['salesOrderInvoice.quotedDate'])">
		    <img onMouseOver="window.status='Click here to select date';return true"  onMouseOut="window.status='';return true" border="0" align='center'
		    src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
          </TD>
		  <TD WIDTH="17%">&nbsp;</TD>
		</TR>
		<TR>
		  <TD WIDTH="7%">&nbsp;</TD>
		  <TD WIDTH="14%">Posting Date:</TD>
		  <TD WIDTH="4%">&nbsp;</TD>
		  <TD WIDTH="16%">
                <nested:text property="postingDate" size ="12" styleClass="txField" maxlength="10" />
            <a href="javascript:openCalendar(document.salesOrderInvoiceForm['salesOrderInvoice.postingDate'])">
		    <img onMouseOver="window.status='Click here to select date';return true"  onMouseOut="window.status='';return true" border="0" align='center'
		    src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>

          </TD>
		  <TD WIDTH="4%">&nbsp;</TD>
		  <TD WIDTH="14%">Order Date:</TD>
		  <TD WIDTH="2%">&nbsp;</TD>
		  <TD WIDTH="18%">
            <nested:text property="orderDate" size ="12" styleClass="txField" maxlength="10"  disabled = "true"/>
            <%--<a href="javascript:openCalendar(document.salesOrderInvoiceForm['salesOrderInvoice.orderDate'])">
		    <img onMouseOver="window.status='Click here to select date';return true"  onMouseOut="window.status='';return true" border="0" align='center'
		    src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a> --%>

          </TD>
		  <TD WIDTH="17%">&nbsp;</TD>
		</TR>
		<TR>
        <!-- Quote Number and Sales Order Number added by devi on 13 March 2004  -->
        <TR>
		  <TD WIDTH="41%" colspan="4">&nbsp;</TD>
		  <TD WIDTH="4%">&nbsp;</TD>
		  <!--TD WIDTH="14%">Sales Order No:</TD-->
		  <TD WIDTH="14%">&nbsp;</TD>
		  <TD WIDTH="2%">&nbsp;</TD>
		  <TD WIDTH="18%">&nbsp;
            <!--nested:text property="salesOrderNumber" size ="12" styleClass="txField" maxlength="10" /-->
          </TD>
		  <TD WIDTH="17%">&nbsp;</TD>
		</TR>
		<TR>
		  <TD WIDTH="100%" colspan = "9">&nbsp;</TD>
		</TR>
	  </TABLE>
    <TABLE BORDER="0" WIDTH="100%" CLASS="NArialL" align="center">
        <TR>
            <TD WIDTH = "100%" COLSPAN="9">
                <logic:equal name="AutoSalesOrderInvoice" value="true" scope="session">
                     Sales Order Number : <nested:select property="selectedSONumber" styleClass="txfield" disabled="true">
                    <html:options collection = "soNumberList" property="value" labelProperty="label" />
                    </nested:select>&nbsp;&nbsp;&nbsp;&nbsp;
                </logic:equal>
                <logic:notEqual name="AutoSalesOrderInvoice" value="true" scope="session">
                     Sales Order Number : <nested:select property="selectedSONumber" styleClass="txfield" disabled="true">
                    <html:options collection = "soNumberList" property="value" labelProperty="label" />
                    </nested:select>&nbsp;&nbsp;&nbsp;&nbsp;
                    <!-- chiptrack:restrictedLink functionality="< %=Functionality.SALES_ORDER_INVOICE%>"
                    action="< %=User.USER_ACTION_MODIFY%>"href="javascript:loadBySONumber()" onmouseover="window.status='Click here To add a new Line Item';return true" onmouseout="window.status='';return true">
                    <IMG SRC="< %=chipTracContext%>/jsp/includes/images/addmore.gif" ALIGN="BOTTOM" BORDER="0" >
                    < /chiptrack:restrictedLink -->
                </logic:notEqual>
            </TD>
        </TR>
        <TR>
            <TD WIDTH = "100%" COLSPAN="9">
                <FONT id="lineItemErrors" styleClass="NArialL" color="red" size="1"></FONT>
            </TD>
        </TR>
	    <TR BGCOLOR="#990000">
		  <TD WIDTH="4%">
		    <P ALIGN="CENTER"><B><FONT COLOR="white">S.No</FONT></B>
		  </TD>
		  <TD WIDTH="15%">
		    <P ALIGN="CENTER"><B><FONT COLOR="white">Sales Order Number</FONT></B>
		  </TD>
          <TD WIDTH="15%">
		    <P ALIGN="CENTER"><B><FONT COLOR="white">Mfg.Part Number</FONT></B>
		  </TD>
		  <TD WIDTH="11%">
		    <P ALIGN="CENTER"><B><FONT COLOR="white">Quantity</FONT></B>
		  </TD>
		  <TD WIDTH="8%" >
		    <P ALIGN="CENTER"><B><FONT COLOR="white">Unit Cost($)</FONT></B>
		  </TD>
		  <TD WIDTH="20%">
		    <P ALIGN="CENTER"><B><FONT COLOR="white">Description</FONT></B>
		  </TD>
		  <TD WIDTH="8%" nowrap>
		    <P ALIGN="CENTER"><B><FONT COLOR="white">Unit Price($)</FONT></B>
		  </TD>
		  <TD WIDTH="9%" nowrap>
		    <P ALIGN="CENTER"><B><FONT COLOR="white">MarkDown($)</FONT></B>
		  </TD>
		  <TD WIDTH="10%">
		    <P ALIGN="CENTER"><B><FONT COLOR="white">Extended Price($)</FONT></B>
		  </TD>
		  <TD WIDTH="15%" BGCOLOR="white">&nbsp;</TD>
		</TR>
        <nested:iterate id="salesOrderInvoiceLineItem" property="salesOrderInvoiceLineItemList" type="com.scalar.chiptrack.sales.SalesOrderInvoiceLineItem" >
		<TR>
          <TD WIDTH="4%" BGCOLOR="#DEE1E2">
		    <P ALIGN="CENTER">
            <nested:write property="invoiceIndex" />
            <nested:hidden property="invoiceIndex" />

            <nested:hidden property="invoiceLineItemSequenceNo"/>
            <!-- Hidden field stores the no of Line items available for a Sales Invoices -->
            <nested:hidden property="lineItemCount" />
		  </TD>
          <TD WIDTH="15%" BGCOLOR="#DEE1E2">
            <nested:hidden property="disableCheckBox" />
            <!-- Modified on march 21st-->
            <% String rowNo = "javascript:onCheckBoxChange(" + i + ")"; %>
            <nested:checkbox property="lineItemSave" styleClass="txfield" onclick="<%=rowNo%>"  />&nbsp;
            <nested:text property="salesOrderNumber" size = "21" styleClass="txfield" readonly="true" disabled="true"/>
		  </TD>
          <TD WIDTH="15%" BGCOLOR="#DEE1E2">
            <!--nested:select property="marketingPartNo" styleClass="txfield" onchange="javascript:itemOnChange(this);">
                <option value = "">---- Select ----</option>
                <!--html:options collection = "partNumberList" property="value" labelProperty="label"/>
            <!--/nested:select-->
            <nested:text property="marketingPartNo" styleClass="txfield" readonly="true" disabled="true"/>
		  </TD>
          <TD WIDTH="11%" BGCOLOR="#DEE1E2" ALIGN="RIGHT">
		    <P><nested:text property="quantity" size ="10" styleClass="valuetxField" maxlength="9" onchange="javascript:calculateTotal();" onkeypress="javascript:numericFieldKeyPress( this )"/>
		  </TD>
		  <TD WIDTH="8%" BGCOLOR="#DEE1E2" ALIGN="RIGHT">
		    <P><nested:text property="unitCost" size ="17" styleClass="valuetxField" maxlength="9" readonly="true" disabled="true"/>
		  </TD>
		  <TD WIDTH="20%" BGCOLOR="#DEE1E2">
		    <P><nested:textarea property="lineItemDescription" styleClass="txField" onkeypress="javascript:checkDescriptionLength(this)"/>
		  </TD>
		  <TD WIDTH="8%" BGCOLOR="#DEE1E2" ALIGN="RIGHT">
		    <P><nested:text property="unitPrice" size ="17" styleClass="valuetxField" maxlength="9" onchange="javascript:calculateTotal();" onkeypress="javascript:amountFieldKeyPress( this )"/>
		  </TD>
		  <TD WIDTH="9%" BGCOLOR="#DEE1E2" ALIGN="RIGHT">
		    <P><nested:text property="markDown" size ="17" styleClass="valuetxField" maxlength="9" onchange="javascript:calculateTotal();" onkeypress="javascript:amountFieldKeyPress( this )"/>
		  </TD>
		  <TD WIDTH="10%" BGCOLOR="#DEE1E2" ALIGN="RIGHT">
		    <P><nested:text property="extendedPrice" size ="17" styleClass="valuetxField" maxlength="9" onchange="javascript:calculateExtendedPrice();" onkeypress="javascript:amountFieldKeyPress( this )"/>
		  </TD>
		  <TD WIDTH="15%">&nbsp;</TD>
		</TR>
       <% i++;%>
       </nested:iterate>
       </TABLE>
        <TABLE BORDER="0" WIDTH="100%" CLASS="NArialL" align="center">
	    <TR>
		  <TD WIDTH="4%">&nbsp;</TD>
		  <TD WIDTH="15%">&nbsp;</TD>
		  <TD WIDTH="11%">&nbsp;</TD>
		  <TD WIDTH="8%">&nbsp;</TD>
		  <TD WIDTH="20%">&nbsp;</TD>
		  <TD WIDTH="16%">&nbsp;</TD>
		  <TD WIDTH="13%">
            Sub Total:
		  </TD>
		  <TD WIDTH="15%" ALIGN="RIGHT">
            <P>$<nested:text property="subTotal" styleClass="valuetxfield" size="17" disabled = "true" />
		  </TD>
		  <TD WIDTH="1%">&nbsp;</TD>
		  <!--TD WIDTH="18%">&nbsp;</TD-->
		</TR>
		<TR>
          <TD WIDTH="19%" colspan="2" >
            Amount Received:
		  </TD>
          <TD WIDTH="37%" colspan="3">
		    <p>&nbsp;&nbsp;$<nested:text property="amountReceived" size ="17" styleClass="valuetxField" maxlength="9" onchange="javascript:calculateTotal();" onkeypress="javascript:amountFieldKeyPress( this )"/>
		  </TD>
		  <TD WIDTH="16%">&nbsp;</TD>
		  <TD WIDTH="13%">
            Trade Discount:
		  </TD>
		  <TD WIDTH="15%" align="right">
		    <P>$<nested:text property="tradeDiscount" size ="17" styleClass="valuetxField" maxlength="9" onchange="javascript:calculateTotal();" onkeypress="javascript:amountFieldKeyPress( this )"/>
		  </TD>
		  <!--TD WIDTH="18%">&nbsp;</TD-->
		  <TD WIDTH="1%">&nbsp;</TD>
		</TR>
        <TR>
          <TD WIDTH="19%" colspan="2" >
            <nested:equal property="invoiceDocumentTypeId" value="1" >
                Terms&nbsp;Discount&nbsp;Taken:
            </nested:equal>
            <nested:notEqual property="invoiceDocumentTypeId" value="1" >
                Discount&nbsp;Returned:
            </nested:notEqual>
		  </TD>
          <TD WIDTH="37%" colspan="3">
            <p>&nbsp;&nbsp;$<nested:text property="discountTaken" size ="17" styleClass="valuetxField" maxlength="9" onchange="javascript:calculateTotal();" onkeypress="javascript:amountFieldKeyPress( this )"/>
		  </TD>
		  <TD WIDTH="16%">&nbsp;</TD>
		  <TD WIDTH="13%">
            Freight:
		  </TD>
		  <TD WIDTH="15%" align="right">
		    <P>$<nested:text property="freight" size ="17" styleClass="valuetxField" maxlength="9" onchange="javascript:calculateTotal();" onkeypress="javascript:amountFieldKeyPress( this )"/>
		  </TD>
		  <!--TD WIDTH="18%">&nbsp;
                <!--chiptrack:restrictedLink functionality="<%//=Functionality.SALES_ORDER_INVOICE%>"
                    action="<%//=User.USER_ACTION_MODIFY%>"href="javascript:purchaseTaxScheduleEntry()" onmouseover="window.status='Click here to add Purchase Tax Schedule';return true" onmouseout="window.status='';return true">
                    <IMG SRC="<%//=chipTracContext%>/jsp/includes/images/arrow.gif" WIDTH="14" HEIGHT="15" ALIGN="BOTTOM" BORDER="0">
                <!--/chiptrack:restrictedLink-->
          <!--/TD-->
		  <TD WIDTH="1%">&nbsp;</TD>
		</TR>
        <TR>
          <TD WIDTH="19%" colspan="2" >
            On Account:
		  </TD>
          <TD WIDTH="37%" colspan="3">
            <p>&nbsp;&nbsp;$<nested:text property="accountAmount" size ="17" styleClass="valuetxField" readonly="true" disabled="true"/>
		  </TD>
		  <TD WIDTH="16%">&nbsp;</TD>
		  <TD WIDTH="13%">
            Miscellaneous:
		  </TD>
		  <TD WIDTH="15%" align="right">
		    <P>$<nested:text property="miscellaneous" size ="17" styleClass="valuetxField" maxlength="9" onchange="javascript:calculateTotal();" onkeypress="javascript:amountFieldKeyPress( this )"/>
		  </TD>
		  <!--TD WIDTH="18%">&nbsp;
                <!--chiptrack:restrictedLink functionality="<%//=Functionality.SALES_ORDER_INVOICE%>"
                    action="<%//=User.USER_ACTION_MODIFY%>"href="javascript:purchaseTaxScheduleEntry()" onmouseover="window.status='Click here to add Purchase Tax Schedule';return true" onmouseout="window.status='';return true">
                    <IMG SRC="<%//=chipTracContext%>/jsp/includes/images/arrow.gif" WIDTH="14" HEIGHT="15" ALIGN="BOTTOM" BORDER="0">
                <!--/chiptrack:restrictedLink-->
          <!--/TD-->
		  <TD WIDTH="1%">&nbsp;</TD>
		</TR>
        <TR>
          <TD WIDTH="19%" colspan="2" >
           Comment:
		  </TD>
          <TD WIDTH="37%" colspan="3" >&nbsp;</TD>
		  <TD WIDTH="16%">&nbsp;</TD>
		  <TD WIDTH="13%">
            Tax:
		  </TD>
		  <TD WIDTH="15%" align="right">
		    <P>$<nested:text property="tax" size ="17" styleClass="valuetxField" maxlength="9" onchange="javascript:calculateTotal();" onkeypress="javascript:amountFieldKeyPress( this )" />
		  </TD>
		  <!--TD WIDTH="18%">&nbsp;
                <!--chiptrack:restrictedLink functionality="<%//=Functionality.SALES_ORDER_INVOICE%>"
                    action="<%//=User.USER_ACTION_MODIFY%>"href="javascript:purchaseTaxScheduleEntry()" onmouseover="window.status='Click here to add Purchase Tax Schedule';return true" onmouseout="window.status='';return true">
                    <IMG SRC="<%//=chipTracContext%>/jsp/includes/images/arrow.gif" WIDTH="14" HEIGHT="15" ALIGN="BOTTOM" BORDER="0">
                <!--/chiptrack:restrictedLink-->
          <!--/TD-->
		  <TD WIDTH="1%">&nbsp;</TD>
		</TR>
        <TR>
		  <TD WIDTH="58%" colspan="5" rowspan="3">
            <nested:textarea property="commentDescription" rows="4" cols="80" styleClass="txField" onkeypress="javascript:checkCommentLength(this)"/>
            <nested:hidden property="commentId"/>
		  </TD>
		  <TD WIDTH="16%">&nbsp;</TD>
		  <TD WIDTH="13%">
            Total:
		  </TD>
		  <TD WIDTH="15%" align="right">
            <P>$<nested:text property="total" size ="17" styleClass="valuetxField" disabled="true" readonly="true"/>
		  </TD>
		  <!--TD WIDTH="18%">&nbsp;</TD-->
		  <TD WIDTH="1%">&nbsp;</TD>
		</TR>
		<TR>
          <TD WIDTH="100%" colspan="9" >&nbsp;</TD>
		</TR>
        <TR>
          <TD WIDTH="100%" colspan="9" >&nbsp;</TD>
		</TR>
        <TR>
          <TD WIDTH="19%" colspan="2" >&nbsp;</TD>
          <TD WIDTH="37%" colspan="3">&nbsp;</TD>
		  <TD WIDTH="16%">&nbsp;</TD>
		  <TD WIDTH="13%">&nbsp;
            <!--chiptrack:restrictedLink functionality="<%//=Functionality.SALES_ORDER_INVOICE%>"
                action="<%//=User.USER_ACTION_MODIFY%>"href="javascript:addLineItem()" onmouseover="window.status='Click here to add a new Line Item';return true" onmouseout="window.status='';return true">
                <IMG SRC="<%//=chipTracContext%>/jsp/includes/images/addmore.gif" ALIGN="BOTTOM" BORDER="0" >
            <!--/chiptrack:restrictedLink-->
		  </TD>
		  <TD WIDTH="15%" align="right">&nbsp;</TD>
		  <!--TD WIDTH="18%">&nbsp;</TD-->
		  <TD WIDTH="1%">&nbsp;</TD>
		</TR>

       </TABLE>
	</TD>
  </TR>
	<TR>
	    <TD WIDTH="80%">&nbsp;
			<TABLE BORDER="0" WIDTH="100%">

				<TR>
				    <TD WIDTH="25%">&nbsp;</TD>
					<TD WIDTH="30%">
						<P ALIGN="CENTER">
                            <chiptrack:restrictedLink functionality="<%=Functionality.SALES_ORDER_INVOICE%>"
                                action="<%=User.USER_ACTION_MODIFY%>"href="javascript:confirmInvoice();" onmouseover="window.status='Click to Save Sales Order Invoice values';return true" onmouseout="window.status='';return true">
                                <IMG SRC="<%=chipTracContext%>/jsp/includes/images/save.gif" ALIGN="BOTTOM" BORDER="0" title="Click here to Save Sales Order Invoice">
                            </chiptrack:restrictedLink>
                            <A href="salesOrderInvoice.do" onmouseover="window.status='Click to Cancel and go back';return true" onmouseout="window.status='';return true" title="Click here to Cancel and go Back">
                                <IMG SRC="<%=chipTracContext%>/jsp/includes/images/cancel.gif" WIDTH="53" HEIGHT="17" ALIGN="BOTTOM" BORDER="0"></a>
                            <A href="javascript:reset()" onmouseover="window.status='Click to Reset '; return true" onmouseout="window.status='';return true" title="Click here to Reset">
                                <IMG SRC="<%=chipTracContext%>/jsp/includes/images/reset.gif" ALIGN="BOTTOM" BORDER="0">
                            </A>
                    </TD>
					<TD WIDTH="25%">&nbsp;</TD>
				</TR>
            </nested:nest>
            <input type= "hidden" name = "count" value="<%=i%>">
            </html:form>
			</TABLE>
		</TD>
	</TR>
</TABLE>
</TD>
</TR>
<SCRIPT language="javascript">
var form = document.salesOrderInvoiceForm;
</SCRIPT >

<%@ include file = "/jsp/includes/footer.jsp"%>
</TABLE>
</BODY>

</html>